import { Controller, Get, Post, Body, Param, Query, Headers } from '@nestjs/common';
import { TenantService } from './tenant.service';
import { AddTenantDto, GetTenantPageDto, UpdateBaseInfoConfigDto } from './tenant.dto'

@Controller('admin/tenant')
export class TenantController {
  constructor(private readonly tenantService: TenantService) { }


  @Get('publicinfo/:id')
  getTenantPublicInfoById(@Param('id') id: string) {
    return this.tenantService.getTenantPublicById(id);
  }

  @Get('public/:domain')
  getTenantPublicInfoByDomain(@Param('domain') domain: string) {
    return this.tenantService.getTenantPublicInfoByDomain(domain);
  }

  @Post('add')
  addTenant(@Body() addTenantDto: AddTenantDto) {
    return this.tenantService.addTenant(addTenantDto);
  }

  @Get('page')
  getTenantPage(@Query() getTenantPageDto: GetTenantPageDto) {
    return this.tenantService.getTenantPage(getTenantPageDto);
  }
}

@Controller('admin/sysTenantConfig')
export class SysTenantConfigController {
  constructor(private readonly tenantService: TenantService) { }


  @Get('getByKey/:key')
  getTenantConfigByKey(@Param('key') key: string, @Headers() headers) {
    const tenantId = headers['tenant-id']
    return this.tenantService.getTenantConfigByKey(key, +tenantId);
  }

  @Post('update/baseInfoConfig')
  updateBaseInfoConfig(@Body() updateBaseInfoConfigDto: UpdateBaseInfoConfigDto, @Headers() headers) {
    const tenantId = headers['tenant-id']
    return this.tenantService.updateBaseInfoConfig(+tenantId, updateBaseInfoConfigDto);
  }

}
